﻿using System;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Xml.Serialization;
using FeedReaderSample.Model;
using FeedReaderSample.Service;
using INdTFramework.Extensions;
using Microsoft.Phone.Controls;

namespace FeedReaderSample
{
    public partial class MainPage : PhoneApplicationPage
    {
        private News _news;
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            RssService rss = new RssService();
            rss.GetFeeds(success => 
                {
                    _news = success;
                    RssImage.HolderImage = new BitmapImage (new Uri (_news.Channel.Image.Url));

                    FeedsListBox.ItemsSource = _news.Channel.Items;
                }, 
                fail => { });
        }

        private void SendButtonClicked(object sender, EventArgs e)
        {
            XmlSerializer serializer = new XmlSerializer(_news.GetType());
            String output = serializer.SerializeToString(_news);

            MessageBox.Show(output);
        }
    }
}